#!/bin/sh -e

rm -rf dist config/data/assets.json

npm install

node_modules/.bin/esbuild "$@"         \
    --asset-names=[dir]/[name]-[hash]  \
    --bundle                           \
    --entry-names=[dir]/[name]-[hash]  \
    --format=esm                       \
    --inject:js/_inject.ts             \
    --jsx-factory=createElement        \
    --loader:.svg=copy                 \
    --loader:.woff2=file               \
    --metafile=config/data/assets.json \
    --minify                           \
    --outbase=.                        \
    --outdir=dist                      \
    --public-path=/dist                \
    --sourcemap                        \
    --target=es2020,chrome88           \
    `find css js svg -type f -not -name '_*' -not -path '*/vendor/*'`
